{% extends '_base_list.html' %}

{% block title %}
    作业中心
{% endblock %}


{% block top_css %}
    {{ super() }}
    <!--bees-->
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bees.css') }}">
{% endblock %}


<!-- Content head -->
{% block head_title %}
    作业中心
{% endblock %}
{% block head_nav %}
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i></a></li>
        <li><a href="#">日志审计</a></li>
        <li class="active">FTP日志</li>
    </ol>
{% endblock %}


<!-- Content body -->
{% block title_filter %}
    <div class="filter">
        <div class="row">
            <div class="col-xs-12 col-sm-2">
                <div class="form-group">
                    <input type="text" class="form-control" name="create_time" placeholder="请选择创建时间" autocomplete="off">
                </div>
            </div>
            <div class="col-xs-12 col-sm-3 pull-right">
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" name="" placeholder="请输入角色名称" class="form-control">
                        <span class="input-group-btn">
                            <button name="search" class="btn btn-mint" type="button">
                                <i class="fa fa-search"></i>
                            </button>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block body_operator %}
{% endblock %}

{% block body_table %}
   <table id="sftpTable" class="table table-auto">
   </table>
{% endblock %}


{% block buttom_js %}
    {{ super() }}
    <!--bees-->
    <script src="{{ url_for('static', filename='js/bees.js') }}"></script>

    <script type="text/javascript">

        $(function () {
            bees.activeMenuNav('.terminal-log-sftp');

            bees.initDaterangepicker($('input[name="create_time"]'),{
                opens: "right",
                timePicker: false,
                timePickerSeconds: false,
                singleDatePicker: false,
                locale: {
                    format: 'YYYY-MM-DD'
                }
            });

            // 回填和初始化默认过滤参数
            var createTimeEle = $("input[name='create_time']");
            var searchEle = $('input[name="search"]');

            var filterParams = JSON.parse(window.sessionStorage.getItem("filterParams"));
            if(filterParams){
                // 回填表单过滤条件
                createTimeEle.val(filterParams.create_time);
                searchEle.val(filterParams.search);
                window.sessionStorage.removeItem("filterParams");
            }else {
                // 默认表单过滤条件
                filterParams = {
                    'create_time': createTimeEle.val(),
                    'search': searchEle.val()
                };
            }
            $.fn.beesTable.defaultFilterParams(filterParams);

            // 初始化表格
            var $tableEle = $("#sftpTable");
            var options = {
                columns: [
                    {title: '', field: 'selected', radio: true},
                    {title: '用户', field: 'user', sortable: false},
                    {title: '资产', field: 'asset', sortable: false},
                    {title: '系统用户', field: 'system_user', sortable: false},
                    {title: '远程地址', field: 'remote_addr', sortable: false},
                    {title: '操作', field: 'operate', sortable: false},
                    {title: '文件名', field: 'filename', sortable: false},
                    {title: '是否成功', field: 'is_success', sortable: false,
                        formatter: function (value, row, index, field) {
                            if(value == 0){
                                return '<i class="fa fa-close text text-danger"></i>'
                            }else if(value == 1){
                                return '<i class="fa fa-check text text-success"></i>'
                            }else{
                                return '<i class="fa fa-circle-o text text-warning"></i>'
                            }
                        }
                    },
                    {title: '创建时间', field: 'create_time', sortable: true}
                ],
                url:'{{ url_for("terminal.api-log-sftp") }}',
                sortName: 'create_time',
                sortOrder: 'desc'
            };
            var table = $tableEle.beesTable(options);

            // 搜索
            bees.bindTableSearch({
                table: $tableEle,
                searches: [
                    {eventType:'change', eventSource:createTimeEle, data:function () {
                            return {'create_time': createTimeEle.val()};
                        }
                    },
                    {eventType:'click', eventSource:$('button[name="search"]'), data: function () {
                            return {'search': searchEle.val()}
                        }
                    }
                ]
            });

            // 操作
            bees.bindTableOperator({
                table: $tableEle,
                operator: {
                    add: {
                        disable: true
                    },
                    show: {
                        disable: true
                    },
                    edit: {
                        disable: true
                    },
                    del: {
                        disable: true
                    }
                }
            })

        })
    </script>
{% endblock %}
